package com.decent.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.decent.dao.BrandMapper;
import com.decent.entity.Brand;
import com.decent.service.BrandService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author decent
 * @Create 2021/4/7 - 16:29
 * @Description
 */
@Service
public class BrandServiceImpl implements BrandService {

    @Resource
    private BrandMapper brandMapper;

    /**
     * 热门权益，显示热门权益品牌，在管理平台标记热门标识才能显示
     *
     * @param pageNumber 页码
     * @param pageSize   每页数量
     * @return id, brandName, iconUrl,attribute
     */
    @Override
    public PageInfo<Brand> listHotBrand(Integer pageNumber, Integer pageSize) {
        return PageHelper.startPage(pageNumber, pageSize).doSelectPageInfo(() -> {
            brandMapper.selectList(Wrappers.<Brand>query()
                    .select("id", "brand_name", "icon_url","attribute")
                    .eq("is_hot","1")
                    .orderByAsc("brand_name"));
        });
    }

    @Override
    public PageInfo<Brand> listBrand(Long brandTypeId, Integer pageNumber, Integer pageSize) {
        return PageHelper.startPage(pageNumber, pageSize).doSelectPageInfo(() -> {
            brandMapper.selectList(Wrappers.<Brand>query()
                    .select("id", "brand_name")
                    .eq("type_id", brandTypeId));
        });
    }
}
